<?php
    if(isset($_POST["sub"])){
        include 'conn.inc.php';
        $sql = "select id from users where name='{$_POST["name"]}'and password='".md5($_POST["password"])."'";
               
        $result = $mysql->Query($sql);

        if($result->num_rows>0){
        	$row = $result->fetch_assoc();
        	$time = time()+60*60*24*7;
        	setCookie("username",$_POST["name"],$time);
        	setCookie("uid",$row["id"],$time);
        	setCookie("isLogin",'ture');

            header("Location:index.php");
        }
        echo "用户名密码有误<br/>";
    }

?>
<html>
<head>
	<meta charset="utf-8"/>
    <title>用户登录页面</title>
</head>
<body>
    <form action="login.php" method="post">
        <table align="center" width="300" border="1">
        	<caption><h1>用户登录</h1></caption>
            <tr>
            	<th>用户名</th>
            	<td><input type="text" name="name"></td>
            </tr>
            <tr>
            	<th>登录密码</th>
            	<td><input type="password" name="password"></td>
            </tr>
            <tr>
            	<td colspan="2" align="center"><!--colspan  指可横跨的列数 默认是1-->
            		<input type="submit" name="sub" value="登录">
            	</td>
            </tr>
        </table>
    </form>
</body>
</html>


















































